package com.one.efaimaly.main.ui.binder;

import android.support.annotation.NonNull;
import android.view.View;
import android.widget.TextView;

import com.one.common.view.multitytype.adapter.BaseItemBinder;
import com.one.common.view.multitytype.adapter.BaseViewHolderMulti;
import com.one.efaimaly.R;
import com.one.common.model.bean.CityBean;

import static com.one.efaimaly.main.presenter.SelectCityPresenter.CUR_CITY;

/**
 * creator: zhulunjun
 * time:    2018/8/6
 * describe:
 */
public class CityBinder extends BaseItemBinder<CityBean> {

    private OnCitySelectListener onCitySelectListener;
    private View.OnClickListener onClickListener;
    public CityBinder(OnCitySelectListener onCitySelectListener, View.OnClickListener onClickListener) {
        super(R.layout.item_city);
        this.onCitySelectListener = onCitySelectListener;
        this.onClickListener = onClickListener;
    }

    @Override
    protected void bindView(@NonNull BaseViewHolderMulti holder, @NonNull final CityBean item) {
        holder.setText(R.id.tv_city, item.getName());
        holder.getView(R.id.ll_city).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(onCitySelectListener!=null){
                    onCitySelectListener.onCitySelect(item);
                }
            }
        });
        TextView reLocation =  holder.getView(R.id.tv_re_location);
        if(item.getFirst_pingyin().equals(CUR_CITY)){
            reLocation.setVisibility(View.VISIBLE);
        }else {
            reLocation.setVisibility(View.GONE);
        }
        reLocation.setOnClickListener(onClickListener);

    }


    public interface OnCitySelectListener{
        void onCitySelect(CityBean bean);
    }
}
